package com.stormrage.edu.dao.edu.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.edu.EduChapterDao;
import com.stormrage.entity.edu.EduChapter;
import com.stormrage.entity.edu.rep.EduChapterRep;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: EduChapterDaoImpl.java
 * @Package com.stormrage.edu.dao.edu.impl
 * @Description: 章节 Dao
 * @author www.stormragetech.com
 * @date 2016年4月8日
 * @version V1.0
 */
@Repository
public class EduChapterDaoImpl extends MysBaseDao implements EduChapterDao {

	private static final Logger logger = LoggerFactory.getLogger(EduCourseDaoImpl.class);

	@Override
	public EduChapter queryById(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduChapterDao 】- 【 QueryById 】- 开始运行 ");

		final String query = "SELECT * FROM edu_chapter WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		EduChapter entity = queryObject(query, EduChapter.class, map);

		logger.debug(" 【 Dao 】- 【 EduChapterDao 】- 【 QueryById 】- 完成运行 ");
		return entity;
	}

	@Override
	public List<EduChapter> queryList() throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduChapterDao 】- 【 QueryList 】- 开始运行 ");

		final String query = "SELECT * FROM edu_chapter";
		logger.debug(" 数据库执行语句为 " + query);

		List<EduChapter> array = queryList(query, EduChapter.class);

		logger.debug(" 【 Dao 】- 【 EduChapterDao 】- 【 QueryList 】- 完成运行 ");
		return array;
	}

	@Override
	public List<EduChapterRep> queryRepListByCourseId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduChapterDao 】- 【 QueryRepListById 】- 开始运行 ");

		final String query = "SELECT a.id, a.chapter FROM edu_chapter AS a, edu_course_chap AS b"
				+ " WHERE a.id = b.chap_id AND b.course_id = :id ORDER BY a.id";
		logger.debug(" 数据库执行语句为 " + query);

		List<EduChapterRep> array = queryList(query, EduChapterRep.class, map);

		logger.debug(" 【 Dao 】- 【 EduChapterDao 】- 【 QueryRepListById 】- 完成运行 ");
		return array;
	}

}
